<?php
	session_start();
	require('game_functions.php');
	$gameid = $_POST['gameid'];
	$type = $_POST['showtype'];
	$name = $type.$gameid;
	$name2 = $name.'SUB';
	
	
	if($_POST['add'] <> ''){
		$insert=
		"insert into DISCUSSION (PLAYER,GAME,POST_DT,POST) 
		values (".$_SESSION['USERNUM'].",".$gameid.",sysdate(), '".clean_data($_POST['add_text'])."')";
		update_g_notes($gameid);
		$result = mysql_query($insert);	
	}
	
	update_p_notes($gameid,$_SESSION['USERNUM']);
	
	dblogin();
	$query="
		select d.player, d.post_dt, d.post 
		from DISCUSSION d
		where d.game = ".$gameid;		
	$result = mysql_query($query);

?>
<script type="text/javascript">
$(document).ready(function(){
    // bind form using ajaxForm 
    $('#<?php echo $name2 ?>').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#<?php echo $name;?>', 
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            $('#<?php echo $name;?>').fadeIn('slow'); 
        }
    }); 
});
</script>
	
<?php	
	if($row = mysql_fetch_array($result)){
?>
	<iframe src="Games/show_discussions.php?gameid=<?php echo $gameid; ?>" style="background: #FFFFFF; width:600px; height: 300px;"/>
<?php
	}else{
?>
	<p> No discussion yet!  Add your two cents! </p>
<?php }
?>	
	<div id="add">
		<form id="<?php echo $name2; ?>" method="post" action="Games/game_discussion.php">
		<input type="hidden" name="gameid" value="<?php echo $gameid; ?>">
		<input type="hidden" name="showtype" value="<?php echo $type; ?>">

		<textarea name="add_text">Add stuff here!</textarea>
		
		<div id="buttons">
			<input type="submit" value="send" name="add">
		</div>
		</form>
	</div>
